package com.example.expresscabinet.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.expresscabinet.common.Result;
import com.example.expresscabinet.model.getexpress;
import com.example.expresscabinet.model.sendexpress;
import com.example.expresscabinet.service.ICabinetService;
import com.example.expresscabinet.service.IFriendService;
import com.example.expresscabinet.service.IGetexpressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/getexpress")
public class getexpressController {

    @Autowired
    IGetexpressService getexpressService;

    @Autowired
    IFriendService friendService;

    @Autowired
    ICabinetService cabinetService;

    //快递员存件操作
    @GetMapping("/add/{tel}/{num}/{expresstel}")
    public Result<?> add(@PathVariable String tel,
                         @PathVariable int num,
                         @PathVariable String expresstel){
        getexpressService.addGetexpress(tel,num,expresstel);
        return Result.success();
    }

    //查询费用
    @GetMapping("/querycost/{code}")
    public Result<?> queryCost(@PathVariable String code){
        int cost=getexpressService.queryCost(code);
        return Result.success(cost);
    }

    // 用户取件操作
    @GetMapping("/take/{tel}/{code}")
    public Result<?> take(@PathVariable String tel,
                         @PathVariable String code){
        int cost=getexpressService.takeGetexpress(code);
        friendService.deleteFriendMsg(tel,code);
        cabinetService.takeEmptyCabinetByCode(code);
        return Result.success(cost);
    }

    //查询用户未取走
    @GetMapping("/querynotake/{tel}")
    public Result<?> querynotake(@PathVariable String tel,
                                 @RequestParam int pageNum,
                                 @RequestParam int pageSize){
        Page<getexpress> res=getexpressService.querynotake(tel,pageNum,pageSize);
        return Result.success(res);
    }

    //查询用户已取走
    @GetMapping("/querytake/{tel}")
    public Result<?> querytake(@PathVariable String tel,
                               @RequestParam int pageNum,
                               @RequestParam int pageSize){
        Page<getexpress> res=getexpressService.querytake(tel,pageNum,pageSize);
        return Result.success(res);
    }

    //查询快递员未取走
    @GetMapping("/querynotakebyexpressman/{expresstel}")
    public Result<?> querynotakebyexpressman(@PathVariable String expresstel,
                                             @RequestParam int pageNum,
                                             @RequestParam int pageSize){
        Page<getexpress> res=getexpressService.querynotakebyexpressman(expresstel,pageNum,pageSize);
        return Result.success(res);
    }

    //查询快递员已取走
    @GetMapping("/querytakebyexpressman/{expresstel}")
    public Result<?> querytakebyexpressman(@PathVariable String expresstel,
                                           @RequestParam int pageNum,
                                           @RequestParam int pageSize){
        Page<getexpress> res=getexpressService.querytakebyexpressman(expresstel,pageNum,pageSize);
        return Result.success(res);
    }
}
